$(function(){
    "use strict";
    // 当点击直接投入的时候
    $('.directInto_box>p').click(function(){
        $(this).siblings('ul.directInto_list').toggleClass('active')
    })
    //当点击核算确定的时候
    $('#check').on('click','.cancel_btn',function(){
        $('#check').removeClass('active')
    })
    // 点击出现搜索框
    $('.hidden_box_showBox').click(function(){
        $(this).siblings('.hidden_box_hiddenBox').toggleClass('active')
        if($(this).children('i').hasClass('icon-jiantou')){
            $(this).children('i').removeClass('icon-jiantou').addClass('icon-jiantou-top')
        }else{
            $(this).children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        }
    })
    // 当确定搜索时
    $('.hiddenBox_list_btn').on('click','button',function(){
        $('.hidden_box_hiddenBox').removeClass('active')
        $('.hidden_box_showBox').children('i').removeClass('icon-jiantou-top').addClass('icon-jiantou')
        if($(this).html() == '确定'){
            $('#dateVal').html(window.query_year_people||'全部')

            let time = $(this).closest('.hidden_box_hiddenBox').find('[data-query="time"]').val()
            let name = $(this).closest('.hidden_box_hiddenBox').find('[data-query="name"]').val()
            window.location.href = `/Admin/ProStaff/index?time=${time}&staff_name=${name}`

        }else{
            window.query_year_people = null
        }
    })
    //当点击查看记录时
    $('#table_table').on('click','.look_record_btn',function(e){
        e.preventDefault()
        $(this).siblings('.tip_hiddenBox').addClass('active')
    })
    // 当点击工时记录中确认按钮时
    $('#table_table').on('click','.work_record_box>.btn',function(e){
        e.preventDefault()
        $(this).parent().removeClass('active')
    })
    //全选的功能
    $('#checkAll').on('click',function(){
        let checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for(let i=0;i<checkboxs.length;i++){
            let checkbox=checkboxs[i];
            if(checkbox.disabled){
                // colnsole.log(11)
                continue
            }else{
                checkbox.checked=this.checked;
            }
        }
    })
    $('#table_table').on('click','input[type=checkbox]:not("#checkAll")',function(){
        "use strict";
        var isCheckedAll = true;
        var checkboxs =$('input[type=checkbox]:not("#checkAll")');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                isCheckedAll = false;
                break;
            }
        }
        $('#checkAll')[0].checked = isCheckedAll;
    })

    /*当点击添加按钮时*/
    $('.operation_btn').on('click','a',function(e){
        e.preventDefault()
        if( $(this).html() == '添加' ){
            var add_people = $(this).attr('href')
            $(`[lll=${add_people}]`).addClass('active')
            let htmls = '<option></option>';
            $.ajax({
                url:'/Admin/Pay/getStaffName',
                type:'get',
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        htmls += `
                            <option value="${data[i].id}" data-dep="${data[i].dep_name}">${data[i].staff_name}</option>
                        `
                    }
                    $(`[lll=${add_people}]`).find('[add_name="add_name"]').html(htmls)
                }
            })
            /*添加默认的1-30*/
        }
        if( $(this).html() == '核算' ){
            var add_people = $(this).attr('href')
            var checkboxs =$('#table_table input[type=checkbox]:not("#checkAll")');
            var len = 0;
            let hs_arr = [];
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择记录！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }else{
                for (let hsi = 0; hsi < checkboxs.length; hsi++) {
                    if (checkboxs[hsi].checked) {
                        hs_arr.push( $(checkboxs[hsi]).closest('tr[data-index]').attr('data-index') )
                    }else{
                        continue;
                    }
                }
                $.ajax({
                    url:'/Admin/ProStaff/calCulStaff',
                    type:'get',
                    data:{
                        id:hs_arr
                    },
                    success:function(data){
                        if(data.fail==0){
                            window.location.href='/Admin/ProStaff/index'
                        }else if(data.code==0){
                            $('#check').find('.check_success_num').html(data.success)
                            $('#check').find('.check_error_num').html(data.fail)
                            $('#check').find('.check_error_Reason').html(data.msg)
                            $(add_people).addClass('active')
                        }else if(data.code==1){
                            if(data.fail==0){
                                $('#check').find('.check_success_num').html(data.success)
                                $('#check').find('.check_error_num').html(data.fail)
                                $('#check').find('.check_error_Reason').remove()
                                $(add_people).addClass('active')
                            }else{
                                $('#check').find('.check_success_num').html(data.success)
                                $('#check').find('.check_error_num').html(data.fail)
                                $('#check').find('.check_error_Reason').html(data.fail_why)
                                $(add_people).addClass('active')
                            }
                        }
                    }
                })
            }


        }
        if( $(this).html() == '批量删除' ){
            var checkboxs =$('input[type=checkbox]:not("#checkAll")');
            var len = 0;
            for (var i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    continue
                }else{
                    len++
                }
            }
            if(len == checkboxs.length){
                $('#yz_modal').html('您还没有选择人员！')
                $('#yz_modal').addClass('active')
                tipShow()
                return
            }
            let _delete = $(this).attr('href');
            $(_delete).addClass('active')
        }
        if( $(this).html() == '批量导入' ){
            let showbox_id = $(this).attr('href');
            $(showbox_id).addClass('active')
        }
    })
    $(`[lll='add_people']`).find('[add_name="add_name"]').change(function(){
        let dep = $(this).children('option:selected').attr('data-dep')
        $(`[lll='add_people']`).find('[add_name="add_department"]').val(dep)
    })
    // 批量删除
    $('.delete_tip_btn_box').on('click','button',function(){
        "use strict";
        let delete_arr = [];
        if($(this).html() == '确认'){
            let checkboxs =$('#table_table input[type=checkbox]:not("#checkAll")');
            for (let i = 0; i < checkboxs.length; i++) {
                if (checkboxs[i].checked) {
                    delete_arr.push( $(checkboxs[i]).closest('tr[data-index]').attr('data-index') )
                }else{
                    continue;
                }
            }
            $.ajax({
                url:'/Admin/ProStaff/multiDelStaff',
                type:'post',
                data:{
                    pro_staff_id: delete_arr
                },
                success:function(data){
                    if(data.code==1){
                        for(let r = 0; r < delete_arr.length; r++){
                            $('#table_table').children('tbody').children(`[data-index=${delete_arr[r]}]`).remove();
                        }
                        $('#delete').removeClass('active')
                        window.location.href = `/Admin/ProStaff/index`//强制刷新
                    }else{
                        $('#yz_modal').html(data.msg)
                        $('#yz_modal').addClass('active')
                        tipShow()
                        return
                    }
                    checkBox()
                }
            })
        }else{
            $('#delete').removeClass('active')
        }
    })
    // 当点击编辑按钮时
    $('#table_table').on('click','.edit_table',function(e){
        e.preventDefault()
        var operation = $(this).attr('href')
        if($(this).html()=='编辑'){
            let operation_id = $(this).closest('tr').attr('data-index');
            let htmls = '';
            $.ajax({
                url:'/Admin/Pay/getStaffName',
                type:'get',
                success:function(data){
                    for(var i=0;i<data.length;i++){
                        htmls += `
                            <option value="${data[i].id}" data-dep="${data[i].dep_name}">${data[i].staff_name}</option>
                        `
                    }
                    $(`[lll=${operation}]`).find('[add_name="edit_name"]').html(htmls)
                }
            })
            $.ajax({
                url:'/Admin/ProStaff/editStaff',
                type:'get',
                data:{
                    id:operation_id
                },
                success:function(data){
                    console.log(data)
                    if(data.code==1){
                        let datas = data.data;
                        // //选择工时
                        // laydate.render({
                        //     elem: '#edit_choose_workTime', //指定元素
                        //     theme: '#2881C1',
                        //     value: datas.start_time+'-01',
                        //     done: function(value, date, endDate){
                        //         // console.log(date)
                        //         let htmls = `
                        //             <li>
                        //                 <span data-day='${date.date}'>${value}:</span>
                        //                 <input type="text" class="BFBFBF_inputStyle add_people_input">
                        //                 <i class='iconfont icon-cha'></i>
                        //             </li>
                        //         `
                                
                        //         $('#edit_workTime_list').append(htmls)
                        //         let len = $('#edit_workTime_list').children('li').length
                        //         $('#edit_people').find('[add_name="edit_workTime"]').val(len*8)
                        //     },
                        //     change:function(value, date, endDate){
                        //         if(date.month!=mon){
                        //             $('#yz_modal').html('不能选择其他月份！')
                        //             $('#yz_modal').addClass('active')
                        //             tipShow()
                        //             $('#edit_workTime_list').html('')
                        //             $('#edit_people').find('[add_name="edit_workTime"]').val('0')
                        //         }
                                
                        //     }
                        // })

                        
                        $(`[lll=${operation}]`).find(`[add_name='start_time_edit']`).val(datas.start_time)
                        // $(`[lll=${operation}]`).find(`[add_name='end_time_edit']`).val(datas.end_time)
                        let max_days = datas.max_days
                        let dayListHtmls = ''
                        for(let i=1; i<=max_days; i++){
                            dayListHtmls+=`<li>${i}</li>`
                        }
                        dayListHtmls+=`
                            <div class='chooseDayBtn_box'>
                                <div>
                                    <button class='chooseDayBtn'>清空</button>
                                    <button class='chooseDayBtn'>确认</button>
                                </div>
                            </div>
                        `
                        $('#editList').attr('data-hours',datas.standard_hours)
                        $('#editList').html(dayListHtmls)

                        $(`[lll=${operation}]`).find(`[add_name='edit_name']`).val(datas.staff_id)
                        $(`[lll=${operation}]`).find(`[add_name='edit_department']`).val(datas.dep_name)
                        $(`[lll=${operation}]`).find(`[add_name='edit_workTime']`).val(datas.work_hours)//工时
                        // $(`[lll=${operation}]`).find(`[add_name='edit_workTimeRecord']`).val(datas.work_record)
                        let work_day = datas.work_day
                        let html = ''
                        let works_daysList = $('#editList').children('li')
                        for(let i=0;i<work_day.length;i++){
                            html += `
                                <li>
                                    <span data-day='${work_day[i].day}'>${work_day[i].date}:</span>
                                    <input type="text" value="${work_day[i].work_hours}" class="input_work_hours BFBFBF_inputStyle add_people_input" style='width:40px !important;margin-right:10px;text-align:center;padding-left:0' placeholder='工时'>
                                    <input type="text" class="BFBFBF_inputStyle add_people_input" placeholder='请输入工时记录' value='${work_day[i].record}'>
                                    <i class='iconfont icon-cha'></i>
                                </li>
                            `
                            for(let j=0; j<works_daysList.length; j++){
                                console.log($(works_daysList[j]).html())
                                console.log(work_day[i].day)
                                if(work_day[i].day==$(works_daysList[j]).html()){
                                    $(works_daysList[j]).addClass('active')
                                }
                            }
                        }
                        $('#edit_workTime_list').html(html)
                        window.sessionStorage['operation_id']=operation_id
                        $(`[lll=${operation}]`).addClass('active');
                    }
                }
            })
        }else{//当他等于取消核算的时候
            let cancel_hesuan_id = $(this).closest('tr[data-index]').attr('data-index')
            let that = this
            $.ajax({
                url: '/Admin/ProStaff/canelStaff',
                type: 'get',
                data: {
                    id: cancel_hesuan_id
                },
                success: function(data){
                    if(data.code==1){
                        console.log(1)
                        $(that).closest('tr[data-index]').find('input').removeAttr('disabled')
                        $(that).html('编辑')
                        $(that).attr('href','edit_people')
                        // window.
                    }
                }
            })
        }

    })
    $(`[lll='edit_people']`).find('[add_name="edit_name"]').change(function(){
        let dep = $(this).children('option:selected').attr('data-dep')
        $(`[lll='edit_people']`).find('[add_name="edit_department"]').val(dep)
    })

    /*选择日期*/
        let chooseDayListArr = []
        $('.chooseDayList').on('click','li',function(){
            let index = $(this).index()+1
            let list = $(this).closest('ul.chooseDayList').children()

            if($(this).hasClass('active')){
                $(this).removeClass('active')
                chooseDayListArr.splice(chooseDayListArr.indexOf(index),1);
            }else{

                if(chooseDayListArr.length<1){
                    $(this).addClass('active')
                    chooseDayListArr.push(index)
                }else{
                    for(let r of chooseDayListArr){
                        for(let i=0;i<list.length;i++){
                            if($(list[i]).html()==r){
                                if(r<index){
                                    for(let k = r; k<index;k++){
                                        $(list[k]).addClass('active')
                                        chooseDayListArr=[]
                                    }
                                }else{
                                    for(let k = index-1; k<r;k++){
                                        $(list[k]).addClass('active')
                                        chooseDayListArr=[]
                                    }
                                }
                            }
                        }
                    }
                }
            }

        })

        $('.chooseDayList').on('click','.chooseDayBtn',function(e){
            e.preventDefault()
            let list = $(this).closest('ul.chooseDayList').children()
            if($(this).html()=='确认'){
                let date = $(this).closest('ul[lll]').children('li:first-child').find('input').val()
                let arr = []
                let htmls = ''
                let hours = $(this).closest('ul.chooseDayList').attr('data-hours')

                for(let i=0; i<list.length; i++){
                    if($(list[i]).hasClass('active')){
                        arr.push($(list[i]).html())
                        // let hours = $(list[i]).attr('data-hours')
                        htmls+=`
                            <li>
                                <span data-day='${$(list[i]).html()}'>${date}-${$(list[i]).html()}:</span>
                                <input type="text" autocomplete="off" value="${hours}" class="input_work_hours BFBFBF_inputStyle add_people_input" style='width:40px !important;margin-right:10px;text-align:center;padding-left:0' placeholder='工时'>
                                <input type="text" autocomplete="off" class="BFBFBF_inputStyle add_people_input" placeholder='请输入工时记录'>
                                <i class='iconfont icon-cha'></i>
                             </li>
                        `
                    }
                }
                $(this).closest('ul[lll]').find('ul.workTime_list').html(htmls)
                
                let work_hours = arr.length*=hours
                $(this).closest('ul[lll]').find('ul.workTime_list').prev().find('input').val(work_hours)
            }else if($(this).html()=='清空'){
                for(let i=0; i<list.length; i++){
                    if($(list[i]).hasClass('active')){
                        $(list[i]).removeClass('active')
                    }
                }
                $(this).closest('ul[lll]').find('ul.workTime_list').html('')
                chooseDayListArr = []
            }

        })

        /*监听所有的工时框的变化*/
        $('.workTime_list').on('blur','.input_work_hours',function(){
            let list = $(this).closest('ul[lll]').find('.workTime_list').children()
            let hours = 0
            for(let i=0; i<list.length; i++){
                hours+=Number($(list[i]).find('.input_work_hours').val())
            }
            $(this).closest('ul[lll]').find('ul.workTime_list').prev().find('input').val(hours)
        })

    // 确认按钮点击时
    $('#add_btn').click(function(){
        let start_time_add = $(this).closest('[lll]').find('[add_name=start_time_add]').val()
        // let end_time_add = $(this).closest('[lll]').find('[add_name=end_time_add]').val()

        let add_name = $(this).closest('[lll]').find('[add_name=add_name] option:selected').text()
        let add_name_id = $(this).closest('[lll]').find('[add_name=add_name]').val()
        let add_department = $(this).closest('[lll]').find('[add_name=add_department]').val()

        let work_list = $('#add_workTime_list').children('li')
        let workTime_arr = []
        for(let i=0;i<work_list.length;i++){
            // console.log($(work_list[i]).children('span').attr('data-day'))
            let day = $(work_list[i]).children('span').attr('data-day')
            let hours = $(work_list[i]).children('input:nth-child(2)').val()
            let record = $(work_list[i]).children('input:nth-child(3)').val()
            let arr2 = []
            arr2.push(day)
            arr2.push(hours)
            arr2.push(record)
            workTime_arr.push(arr2)
        }
        let work_hours = $(this).closest('[lll]').find('[add_name=add_workTime]').val()
        
        if(start_time_add == '' || add_name == '' || add_department == '' || work_hours == '' || work_list.length<=0){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        //防止重复点击按钮
        if( $(this).attr('lock') ) return
        $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/ProStaff/addStaff',
            type:'post',
            data:{
                start_time: start_time_add,
                // end_time: end_time_add,
                staff_id: add_name_id,
                works:workTime_arr,
                work_hours: work_hours,
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    // let peopleTableHTML = $('#table_table').children('tbody').html()
                    let peopleTableHTML = `
                            <tr data-index="${data.id}">
                                    <td><input type="checkbox" class="checkboxStyle"></td>
                                    <td data-name="start_time_edit">${start_time_add.split('-')[0]}-${start_time_add.split('-')[1]}</td>
                                    <td data-name="edit_name">${add_name}</td>
                                    <td data-name="edit_department">${add_department}</td>
                                    <td data-name="edit_workTime">${work_hours}</td>
                                    <td class="look_record" data-name="edit_workTimeRecord">
                                        <a href="#" class="look_record_btn">查看记录</a>
                                        <div class="tip_hiddenBox work_record_box">
                                            <span class="work_record_title">工时记录</span>
                       `
                       let date = data.data
                       peopleTableHTML += '<ul>'
                        for(let i=0;i<date.length;i++){
                            peopleTableHTML += `
                                <li>${date[i].date}:${date[i].record}</li>
                            `
                        }
                        peopleTableHTML += '</ul>'
                       peopleTableHTML += `
                                            <button class="btn btn-sm btn-success">确认</button>
                                        </div>
                                    </td>
                                    <td style><a href="edit_people" class="edit_table">编辑</a></td>
                                </tr>
                    `
                    $('#table_table').children('tbody').prepend(peopleTableHTML)

                    // $(that).closest('[lll]').find('[add_name]').val('')
                    // $('#add_workTime_list').html('')
                    $(that).closest('[lll]').find('[add_name=add_name]').val('')
                    $(that).closest('[lll]').find('[add_name=add_department]').val('')
                    
                    $(that).closest('[lll]').removeClass('active')
                }else{
                    $('#yz_modal').html(data.msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                }
                $(that).removeAttr('lock')
            }
        })

    })
    // 确认并新增按钮点击时
    $('#add_AddNew_btn').click(function(){
        let start_time_add = $(this).closest('[lll]').find('[add_name=start_time_add]').val()
        // let end_time_add = $(this).closest('[lll]').find('[add_name=end_time_add]').val()

        let add_name = $(this).closest('[lll]').find('[add_name=add_name] option:selected').text()
        let add_name_id = $(this).closest('[lll]').find('[add_name=add_name]').val()
        let add_department = $(this).closest('[lll]').find('[add_name=add_department]').val()

        let work_list = $('#add_workTime_list').children('li')
        let workTime_arr = []
        for(let i=0;i<work_list.length;i++){
            // console.log($(work_list[i]).children('span').attr('data-day'))
            // let day = $(work_list[i]).children('span').attr('data-day')
            // let record = $(work_list[i]).children('input').val()
            // let arr2 = []
            // arr2.push(day)
            // arr2.push(record)
            // workTime_arr.push(arr2)
            let day = $(work_list[i]).children('span').attr('data-day')
            let hours = $(work_list[i]).children('input:nth-child(2)').val()
            let record = $(work_list[i]).children('input:nth-child(3)').val()
            let arr2 = []
            arr2.push(day)
            arr2.push(hours)
            arr2.push(record)
            workTime_arr.push(arr2)
        }
        let work_hours = $(this).closest('[lll]').find('[add_name=add_workTime]').val()
        
        if(start_time_add == '' || add_name == '' || add_department == '' || work_hours == '' || work_list.length<=0){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }
        //防止重复点击按钮
        if( $(this).attr('lock') ) return
        $(this).attr('lock','lock')

        let that = this
        $.ajax({
            url:'/Admin/ProStaff/addStaff',
            type:'post',
            data:{
                start_time: start_time_add,
                // end_time: end_time_add,
                staff_id: add_name_id,
                works:workTime_arr,
                work_hours: work_hours,
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    // let peopleTableHTML = $('#table_table').children('tbody').html()
                    let peopleTableHTML = `
                            <tr data-index="${data.id}">
                                    <td><input type="checkbox" class="checkboxStyle"></td>
                                    <td data-name="start_time_edit">${start_time_add.split('-')[0]}-${start_time_add.split('-')[1]}</td>
                                    <td data-name="edit_name">${add_name}</td>
                                    <td data-name="edit_department">${add_department}</td>
                                    <td data-name="edit_workTime">${work_hours}</td>
                                    <td class="look_record" data-name="edit_workTimeRecord">
                                        <a href="#" class="look_record_btn">查看记录</a>
                                        <div class="tip_hiddenBox work_record_box">
                                            <span class="work_record_title">工时记录</span>
                       `
                       let date = data.data
                       peopleTableHTML += '<ul>'
                        for(let i=0;i<date.length;i++){
                            peopleTableHTML += `
                                <li>${date[i].date}:${date[i].record}</li>
                            `
                        }
                        peopleTableHTML += '</ul>'
                       peopleTableHTML += `
                                            <button class="btn btn-sm btn-success">确认</button>
                                        </div>
                                    </td>
                                    <td style><a href="edit_people" class="edit_table">编辑</a></td>
                                </tr>
                    `
                    $('#table_table').children('tbody').prepend(peopleTableHTML)

                    // $(that).closest('[lll]').find('[add_name]').val('')
                    $(that).closest('[lll]').find('[add_name=add_name]').val('')
                    $(that).closest('[lll]').find('[add_name=add_department]').val('')
                    // $(that).closest('[lll]').find('[add_name=add_name]').val('')
                    // $(that).closest('[lll]').find('[add_name=add_name]').val('')
                    // $(that).closest('[lll]').removeClass('active')
                    // $('#add_workTime_list').html('')

                }else{
                    $('#yz_modal').html(data.msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                }
                $(that).removeAttr('lock')
            }
        })
    })
    // 保存按钮点击时
    $('#save_btn').click(function(){
        let start_time_edit = $(this).closest('[lll]').find('[add_name=start_time_edit]').val()
        // let end_time_edit = $(this).closest('[lll]').find('[add_name=end_time_edit]').val()

        let edit_name = $(this).closest('[lll]').find('[add_name=edit_name] option:selected').text()
        let edit_name_id = $(this).closest('[lll]').find('[add_name=edit_name]').val()
        let edit_department = $(this).closest('[lll]').find('[add_name=edit_department]').val()

        let work_list = $('#edit_workTime_list').children('li')
        let workTime_arr = []
        for(let i=0;i<work_list.length;i++){
            // console.log($(work_list[i]).children('span').attr('data-day'))
            // let day = $(work_list[i]).children('span').attr('data-day')
            // let record = $(work_list[i]).children('input').val()
            // let arr2 = []
            // arr2.push(day)
            // arr2.push(record)
            // workTime_arr.push(arr2)
            let day = $(work_list[i]).children('span').attr('data-day')
            let hours = $(work_list[i]).children('input:nth-child(2)').val()
            let record = $(work_list[i]).children('input:nth-child(3)').val()
            let arr2 = []
            arr2.push(day)
            arr2.push(hours)
            arr2.push(record)
            workTime_arr.push(arr2)
        }
        let work_hours = $(this).closest('[lll]').find('[add_name=edit_workTime]').val()
        
        if(start_time_edit == '' || edit_name == '' || edit_department == '' || work_hours == '' || work_list.length<=0){
            $('#yz_modal').html('您有内容没有填写完整！')
            $('#yz_modal').addClass('active')
            tipShow()
            return
        }

        let operation_id = window.sessionStorage['operation_id']
        let that = this
        $.ajax({
            url:'/Admin/ProStaff/editStaff',
            type:'post',
            data:{
                id:operation_id,
                start_time: start_time_edit,
                // end_time: end_time_edit,
                staff_id: edit_name_id,
                works:workTime_arr,
                work_hours: work_hours,
                // work_record:edit_workTimeRecord
            },
            success:function(data){
                console.log(data)
                if(data.code==1){
                    let HTML = ''
                    HTML = `
                            <td><input type="checkbox" class="checkboxStyle"></td>
                            <td data-name="start_time_edit">${start_time_edit.split('-')[0]}-${start_time_edit.split('-')[1]}</td>
                            <td data-name="edit_name">${edit_name}</td>
                            <td data-name="edit_department">${edit_department}</td>
                            <td data-name="edit_workTime">${work_hours}</td>
                            <td class="look_record" data-name="edit_workTimeRecord">
                                <a href="#" class="look_record_btn">查看记录</a>
                                <div class="tip_hiddenBox work_record_box">
                                    <span class="work_record_title">工时记录</span>
                        `
                       let date = data.data
                       HTML += '<ul>'
                        for(let i=0;i<date.length;i++){
                            HTML += `
                                <li>${date[i].date}:${date[i].record}</li>
                            `
                        }
                        HTML += '</ul>'
                       HTML += `
                                    <button class="btn btn-sm btn-success">确认</button>
                                </div>
                            </td>
                            <td style><a href="edit_people" class="edit_table">编辑</a></td>
                    `
                    $('#table_table').children('tbody').find(`tr[data-index=${operation_id}]`).html(HTML)
                    $(that).parent().parent().removeClass('active')
                }
            }
        })


    })
    // 取消按钮点击时
    $('.button_list').on('click','button',function(){
        if($(this).hasClass('cancel_btn')){
            $(this).closest('[lll]').removeClass('active')
        }
    })

    let msg = '文件正在上传，请勿重复点击！'

    // 上传文件
    $('#file_upload').change(function (e) {
        $(this).siblings('.import_tip_btn_box').find('button').removeClass('btn-grey').addClass('btn-success')
        msg = '文件正在上传，请勿重复点击！'
        $(this).siblings('.import_tip_btn_box').find('button').removeAttr('lock')
    })
    $('#import').find('button').click(function(e){
        "use strict";
        e.preventDefault()
        if($(this).hasClass('btn-success')){
            if($(this).html()=='确定导入'){
                //防止重复点击按钮
                if( $(this).attr('lock') ){
                    $('#yz_modal').html(msg)
                    $('#yz_modal').addClass('active')
                    tipShow()
                    return
                }
                $(this).attr('lock','lock')
                let that = this

                var formData = new FormData($("#file_form")[0]);
                $.ajax({
                    async : false,
                    cache : false,
                    type : "post",
                    data : formData,
                    url : '/Admin/ProStaff/importStaff',
                    dataType : 'json',
                    contentType: false, //必须
                    processData: false, //必须
                    success : function(data) {
                        if(data.code==1){
                            $('#import').removeClass('active')
                            window.location.href = `/Admin/ProStaff/index`//强制刷新
                            $(that).removeAttr('lock')
                        }else{
                            msg = data.msg
                            $('#yz_modal').html(msg)
                            $('#yz_modal').addClass('active')
                            tipShow()
                        }
                    }
                })
            }
        }

    })

    // 弹出来的小框框
    function tipShow(){
        window.tipBox = setTimeout(function(){
            // $('#yz_modal').removeClass('active')
            // $('#yz_modal').addClass('fadeOut')
            $('#yz_modal').removeClass('active')
            clearTimeout(tipBox) 
        },2000)
    }
    //关闭所有已选择的框框
    function checkBox(){
        var checkboxs =$('input[type=checkbox]');
        for (var i = 0; i < checkboxs.length; i++) {
            if (!checkboxs[i].checked) {
                continue;
            }else{
                $(checkboxs[i]).attr('checked',false)
            }
        }
    }

    //当点击区域不在导入弹框中时则关闭弹框
    $(document).click(function(e){
        let $this = $(e.target);
        if($this.closest('#import').length==0){
            if($this.attr('href') != '#import' && $this.children().attr('href') != '#import'){
                $('#import').removeClass('active');
            }
        }
    })

    //拖动拖动拖动
        let add_box =document.getElementById("add_people");
        let edit_box =document.getElementById("edit_people");
        add_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='add_people'){
                ev =ev ||event;
                let oLeft = add_box.offsetLeft;
                let oTop = add_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                add_box.onmousemove =function (ev){
                    ev = ev || event;
                    add_box.style.left =ev.clientX-a+'px';
                    add_box.style.top =ev.clientY-b+'px';
                    $(add_box).css({'cursor':'default'})
                }
            }
            
        }
        edit_box.onmousedown = function(ev){
            if($(ev.toElement).attr('id')=='edit_people'){
                ev =ev ||event;
                let oLeft = edit_box.offsetLeft;
                let oTop = edit_box.offsetTop;
                let a =ev.clientX-oLeft;
                let b =ev.clientY-oTop;
                edit_box.onmousemove =function (ev){
                    ev = ev || event;
                    edit_box.style.left =ev.clientX-a+'px';
                    edit_box.style.top =ev.clientY-b+'px';
                    $(edit_box).css({'cursor':'default'})
                }
            }
        
        }
        document.onmouseup =function(){
            add_box.onmousemove =function(){
                null;
            }
            edit_box.onmousemove =function(){
                null;
            }
        }

})